<!--  -->
<template>
  <div class="grammer-study">
    <div class="chose-course-top">
      <div class="header-left">
        <span
          class="back-arrow"
          @click="() => this.$router.push('/reverse')"
        ></span>
      </div>
      <div class="course-title">
        {{ this.$route.query.type === "0" ? "今日学习" : "累计学习" }}
      </div>
      <div class="btn-group"></div>
    </div>
    <div class="list-wrap" v-if="learnList.length">
      <studyList :renderData="learnList"></studyList>
    </div>
    <Empty v-else></Empty>
    <Timetips ref="timetips"></Timetips>
  </div>
</template>

<script>
import { fetchLearningToday, fetchEndTime } from "@/services/reverse";
import { SUCCESS_CODE } from "@/utils/const";
import studyList from "./studyList";
import Empty from "@/components/Empty";
import Timetips from "@/components/Timetips";

export default {
  name: "grammarStudy",
  components: {
    studyList,
    Empty,
    Timetips
  },
  data() {
    return {
      learnList: [],
    };
  },
  computed: {},
  watch: {},
  methods: {
    fetchLearningList() {
      fetchLearningToday(this.$route.query).then((res) => {
        if (res.code === SUCCESS_CODE) {
          this.learnList = res.data.list.map((v) =>
            Object.assign(v, { clickNum: 0 })
          );
        }
      });
    },
  },
  created() {
    this.fetchLearningList();
  },
  mounted() {},
  beforeCreate() {},
  beforeMount() {},
  beforeUpdate() {},
  updated() {},
  beforeDestroy() {
    this.$refs.timetips.stopTimer();
    this.$refs.timetips.stopEndTimer();
  },
  destroyed() {},
  beforeRouteLeave(to, from, next) {
    fetchEndTime(this.$route.query);
    next();
  },
};
</script>
<style lang="less" scoped>
/* @import url(); 引入公共css类 */
.grammer-study {
  display: flex;
  flex-direction: column;
  height: 100%;

  .list-wrap {
    flex: 1;
    overflow-y: auto;
    padding: 30px 40px;
  }
  .chose-course-top {
    display: flex;
    justify-content: space-between;
    position: relative;
    align-items: center;
    height: 80px;
    padding: 0 40px;
    background-color: #fff;
    .anticon {
      font-size: 24px; /* no */
    }

    .header-left {
      flex: 1;
      display: flex;
      align-items: center;
      justify-content: flex-start;
      .back-arrow {
        width: 30px;
        height: 27px;
        background-image: url("~assets/home/btn_back.png");
        background-size: 100%;
        cursor: pointer;
      }
    }

    .course-title {
      width: 100%;
      flex: 1;
      font-size: 20px;
      font-weight: 700;

      .check-title {
        color: #c7c7c7;
      }
    }
    .btn-group {
      flex: 1;
    }
  }
}
</style>
